|
Cola is a programming language similar to Java and C# with some higher level features of Perl and Ruby including first-class regular expressions. It can be compiled for the Microsoft .NET CLR or the Parrot virtual machine. Cola is a compiled language with static type checking, but the designer mixed in some of the features more common to scripting languages like Perl and Ruby. Cola is less of a new language "design" than a mix of several very powerful languages with the following key principles in mind: C++, Java and C# programmers should be immediately comfortable. Convention over Code - Things that are conventional are implicit defaults. The default scope accesses can be configured with compiler flags to remove burden from the language. (See Java/C# public keyword) Low signal-to-noise ratio - Reduced keyword clutter and an emphasis on improved readability and less on controlling access of other programmers. In practice, the use of the word public dominates Java and C# syntax, based on source code analysis. Cola omits the public keyword, and supports C++ style of scope access sections, and provides a single character @ to make a member private. Regular Expressions, Lists and Associative Arrays get special treatment - Most programming involves text manipulation, lists and iteration. Regular expression support dramatically increases the brevity and productivity "power" of a language, but BUILTIN syntax for regular expressions improves the readability of it. In Cola, regex and pattern matching is part of the syntax. Future plans include equal support of inline EBNF grammar syntax and parsing functions. Scriptlets - Cola allows globals functions, or none at all for a simple script. Though the language is compiled, it has a script mode that compiles on the fly. A Hello world program Cola style: // C/Perl-style without classes // Cola package/global methods are static by default, void by default main() // Cola OO-style // classes, methods and constructors public by default, fields private by default class Hello } Use of most of the .NET framework is possible, including generics, interfaces, arrays, as well as the standard enum constants in the various assemblies. The "using" directive imports a namespace just like C#, to allow unqualified names to be used. In general, C# syntax for any .NET framework class or method is identical in Cola. // .NET System.IO.File sample using System.IO; main() // .NET Winforms Example using System.Windows.Forms; main() // .NET SystemXml Example using System.Xml; main() // Oracle.DataAccess sample using Oracle.DataAccess.Client; main() // Automatically initializes x and y and establishes the types of the parameters } Constructor delegation is supported, using the "this" keyword from the constructor. class T } Cola 0.24 implements properties with getters and setters per the C# standard. class T } } Cola provides both prefix and postfix array declaration notation, and both static and dynamic arrays. This is a productivity choice by the author, to improve comfort for diverse programmer background (C/C++ vs Java/C# style), and to reduce notation (static arrays). int = new int(); // postfix, dynamic if no size specified int() arr; // prefix, dynamic, requires a new int arr(); // postfix, static auto-allocated int arr() = ; // postfix, static auto-allocated and initialized int arr; return default(T); } } // constructor new() // methods void Push(T item) T Pop() } main() io.println("Stack has " + stack.Length + " items"); io.println("Top item is " + stack.Top); io.println(stack.Pop()); io.println(stack.Pop()); io.println("Stack has " + stack.Length + " items"); } The current version of the Cola compiler for .NET is available from the website 〔(Cola Programming Language ).〕 == References == 〔 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Cola (programming language)」の詳細全文を読む スポンサード リンク
|